Page({
  data: {
    title: '登录',
    phone: '',
    yzm: '',
    showText: true,
    second: 60
  },

  bindPhoneInput: function (e) {
    this.setData({
      phone: e.detail.value
    });
  },

  bindCodeInput: function (e) {
    this.setData({
      yzm: e.detail.value
    });
  },

  getCode: function () {
    wx.showToast({ title: '获取验证码', icon: 'none' });
    // 获取验证码的逻辑
    this.setData({
      showText: false
    });
    // 倒计时逻辑
    let that = this;
    let second = that.data.second;
    let interval = setInterval(function () {
      second--;
      that.setData({
        second: second
      });
      if (second <= 0) {
        clearInterval(interval);
        that.setData({
          showText: true,
          second: 60
        });
      }
    }, 1000);
  },

  login: function (e) {
    var that = this;
    if (!that.data.phone) {
      wx.showToast({ title: '请输入手机号', icon: 'none' });
      return;
    }
    if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(that.data.phone)) {
      wx.showToast({ title: '请输入正确手机号', icon: 'none' });
      return;
    }
    if (!that.data.yzm) {
      wx.showToast({ title: '请输入验证码', icon: 'none' });
      return;
    }
    // 此处省略，这里需要调用后台验证一下验证码是否正确，根据您的需求来
    wx.showToast({ title: '登录成功！', icon: 'none' });
  },

  wxLogin: function () {
    wx.showToast({ title: '微信登录', icon: 'none' });
  },

  zfbLogin: function () {
    wx.showToast({ title: '支付宝登录', icon: 'none' });
  },

  onLoad: function () {},

  onReady: function () {},

  onShow: function () {},

  onHide: function () {},

  onUnload: function () {},

  onPullDownRefresh: function () {},

  onReachBottom: function () {},

  onShareAppMessage: function () {}
});